/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.fimuni.pa165.restfrontend.propertyeditor;

import com.google.gson.Gson;
import cz.fimuni.pa165.backendapi.dto.CompanyDTO;
import java.beans.PropertyEditorSupport;
import org.springframework.web.client.RestTemplate;

/**
 *
 * @author Ondřej Myška
 */
public class CompanyDTOPropertyEditor extends PropertyEditorSupport {

    
    private Gson gson;

    public CompanyDTOPropertyEditor(Gson gson) {
        this.gson = gson;
    }
   
    
    @Override
    public void setAsText(String id) {
         String company = new RestTemplate().getForObject("http://localhost:8080/pa165/rest/company/get/"+id,String.class);
        CompanyDTO companyDTO = gson.fromJson(company, CompanyDTO.class);
        setValue(companyDTO);
    }
    
    
    
    
}
